﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Selectors
{
    public partial class SelectUtility : DialogBase, IDialogBase
    {
        public SelectUtility()
        {
            InitializeComponent();
        }

        #region Asynch Processing (Implements IDialogBase)

        //to start the asynch background worker call - base.StartAsynchWork()

        public override void DoAsynchWork(DoWorkEventArgs e)
        {
            //do whatever needs to be done asynch here (BackgroudWorker_DoWork)


        }

        public override void AsychWorkComplete(object sender, RunWorkerCompletedEventArgs e)
        {
            base.AsychWorkComplete(sender, e);
            //do whatever needs to be done after asynch work complete (BackgroudWorker_RunWorkerCompleted)

        }


        #endregion

        private void SelectProject_Load(object sender, EventArgs e)
        {
            var _DefaultUtility = from utility in Program.LoginResult.Utilities
                              where utility.UtilityId == Program.UserSelections.UtilityId
                              select utility;

            if (_DefaultUtility == null || _DefaultUtility.Count() == 0)
                return;

            List<EntityLibrary.UtilityEntity> _List = new List<EntityLibrary.UtilityEntity>();
            _List.Add(_DefaultUtility.First());

            utilities1.SelectedUtilities = _List;
        }

        private void buttonXOk_Click(object sender, EventArgs e)
        {
            List<EntityLibrary.UtilityEntity> _Utility;
            _Utility = utilities1.SelectedUtilities;

            if (_Utility == null || _Utility.Count == 0)
                Program.UserSelections.UtilityId = -1;
            else
                Program.UserSelections.UtilityId = _Utility[0].UtilityId.Value;

            this.DialogResult = DialogResult.OK;
        }
    }
}
